package com.etooling.framework.utils;

import java.security.NoSuchAlgorithmException;


/**
 * 使用该类管理密码规则,将来支持复杂的密码组合规则算法
 */
public class PasswordRuleMgr {
    // 考虑到密码规则升级的需要,加密存储后的密码,具有特殊的密文前缀"crypto_"
    public static String CryptoPasswordKey = "Digest_MD5_";

    public static String getCryptoPassword(String password) {
        String retVal = password;
        byte[] pass_bytes;
        try {

            pass_bytes = Digest.getMessageDigest(password, Digest.MD5);
            retVal = PasswordRuleMgr.CryptoPasswordKey + Digest.byte2hex(pass_bytes);
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return retVal;
    }

    public static void main(String[] args) {

        // TODO Auto-generated method stub
        System.out.println(PasswordRuleMgr.getCryptoPassword("qwer1234"));
    }
}
